package com.weixin.mp.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import lombok.extern.slf4j.Slf4j;

/**
 * Web MVC 配置
 */
@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    
    @Value("${upload.path:/tmp/uploads}")
    private String uploadPath;
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 确保实际路径以"/"结尾
        String actualPath = uploadPath.endsWith("/") ? uploadPath : uploadPath + "/";
        log.info("配置静态资源路径映射: /uploads/** -> {}", actualPath);
        
        // 添加资源处理器，将/uploads/**请求映射到实际文件路径
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + actualPath);
                
        // 添加其他静态资源的映射
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
} 